package com.cjm.algorithm.tree;

import com.cjm.algorithm.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class Ti257 {
    public static void main(String[] args) {

    }
    List<String> res = new ArrayList<>();
    public List<String> binaryTreePaths(TreeNode root) {
        res.clear();
        if (root == null) return res;
        zouqi(root, new StringBuilder());
        return res;
    }
    private static final String s = "->";
    private void zouqi(TreeNode root, StringBuilder path) {
        if (path.toString().isEmpty()) {
            path.append(root.val);
        } else {
            path.append(s).append(root.val);
        }
        if (root.left == null && root.right == null) {
            res.add(path.toString());
            return;
        }

        if (root.left != null) {
            zouqi(root.left, new StringBuilder(path));
        }
        if (root.right != null) {
            zouqi(root.right, new StringBuilder(path));
        }
    }
}
